package com.bridgeintelligent.tag.bulkload.service.core;

import com.bridgeintelligent.tag.bulkload.service.core.fileload.ConditionBuilder;
import com.bridgeintelligent.tag.constants.bulkload.FileLoadMqMsg;
import com.bridgeintelligent.tag.mapper.FileExportMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by JackCheung on 2019/9/22 7:52 PM.
 */
@AllArgsConstructor
@RestController
@RequestMapping(value = "/mq")
public class TestMQ {

    private RocketMQTemplate rocketMQTemplate;
    private FileLoadDelegate fileLoadDelegate;
    private ObjectMapper objectMapper;
    private FileExportMapper fileExportMapper;
    private ConditionBuilder conditionBuilder;
    private FileLoadHandler fileLoadHandler;
    private static final String SUCCESS_FLAG="2";
    private BulkEventDelegate bulkEventDelegate;
    /**
     * 测试MQ
     *
     * @return
     */
    @GetMapping("/test")
    public Object delIndex(String msg) throws JsonProcessingException {
//        FileExportDto fileExportDto = fileExportMapper.findFileExport("059149EA54E747FF94EDBBC5928F3A2C");
//        List<Filter> filters = new ArrayList<>();
//        FilterGroup filterGroup = conditionBuilder.findFilterGroup("-", "F2F5AE5BD27C422D9173756EEFF888C3", filters).get(0);
////        String[] arr = new String[10];
//        FileLoadResult fileLoadResult = fileLoadHandler.handler(fileExportDto, filterGroup);
//        fileExportMapper.updateFilePath(fileExportDto.getId(), fileLoadResult.getFilePath(),SUCCESS_FLAG,"202005",String.valueOf(fileLoadResult.getNum()));

//        ESUtils.scrollSearch("jacktest_20191011", new FileLoadModel(EsQueryBuilder.buildFilter(filterGroup), arr, arr), hits -> {
//            for (SearchHit hit : hits) {
//                System.err.println(hit.getSourceAsMap());
//            }
//        });
//        fileLoadDelegate.onMessage(objectMapper.writeValueAsString(new FileLoadMqMsg("066A0FB9C68F4251A8F066A81023E3F4")));
//        FileLoadMqMsg fileLoadMqMsg = new FileLoadMqMsg("8D259E55F0824BA4A7A164FE6E078D8C");
//        try {
//            String msg = objectMapper.writeValueAsString(fileLoadMqMsg);
////            rocketMQTemplate.convertAndSend(MQConfig.FILE_LOAD_TAG_TOPIC, msg);
//            fileLoadDelegate.onMessage(msg);
//        } catch (JsonProcessingException e) {
//            e.printStackTrace();
//        }
//        String sendMsg="{\"dimId\":\"5198235787085824\",\"filePath\":\"/root/tag/data/5198235787085824/5198235787085824.txt\",\"originalFile\":\"/root/tag/data/5198235787085824/5198235787085824.txt\",\"itemNo\":\"\",\"type\":0,\"classify\":\"03\",\"ecifFlag\":false}";
//        bulkEventDelegate.dispense(sendMsg);
        FileLoadMqMsg fileLoadMqMsg=new FileLoadMqMsg();
        fileLoadMqMsg.setId("8A9BA84B9C1F4E5991BB9378E90C7278");
        fileLoadDelegate.onMessage(objectMapper.writeValueAsString(fileLoadMqMsg));
        return "s";
    }
}
